package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.services.business.dto.response.VehicleNameBizDto;
import com.molichuxing.services.infrastructure.bean.VehicleBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.VehicleMapper;
import com.molichuxing.services.infrastructure.dto.response.VehicleDto;
import com.molichuxing.services.infrastructure.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * 车型 服务实现类
 * </p>
 *
 * @author
 * @since 2019-08-12
 */
@Service("vehicleService")
public class VehicleServiceImpl implements VehicleService {

    @Autowired
    private VehicleMapper vehicleMapper;


    @Override
    public VehicleDto getVehicleByVehicleId(Integer vehicleId) {
        if (null == vehicleId) {
            return null;
        }
        //根据车型id 获取车型信息
        VehicleBean vehicleBean = vehicleMapper.getVehicleById(vehicleId);
        return Convert.toVehicleBeanDto(vehicleBean);
    }

    @Override
    public List<VehicleDto> getVehicleByVehicleIds(List<Integer> vehicleIds) {
        if (null == vehicleIds || vehicleIds.size() == 0) {
            return null;
        }
        List<VehicleDto> result = new ArrayList<>();
        for (Integer vehicleId : vehicleIds) {
            VehicleBean vehicleBean = vehicleMapper.getVehicleById(vehicleId);
            result.add(Convert.toVehicleBeanDto(vehicleBean));
        }
        return result;
    }

    @Override
    public VehicleDto getVehicleByVehicleName(String vehicleName) {
        //根据车型id 获取车型信息
        VehicleBean vehicleBean = vehicleMapper.getVehicleByName(vehicleName);
        return Convert.toVehicleBeanDto(vehicleBean);
    }

    @Override
    public List<VehicleDto> getVehicleList(Integer vehicleModleId) {
        return Convert.toVehicleBeanDto(vehicleMapper.getVehicleList(vehicleModleId));
    }

    @Override
    public List<VehicleDto> getVehicleListByIds(Integer vehicleModleId, List<Integer> vehicleIds) {
        return Convert.toVehicleBeanDto(vehicleMapper.getVehicleListByIds(vehicleModleId, vehicleIds));
    }

    @Override
    public Paged<VehicleDto> getVehiclePage(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        long pageCount = vehicleMapper.getPageCount(map);
        if (pageCount < 1) {
            return new Paged<VehicleDto>();
        }

        List<VehicleBean> vehicleBeanList = vehicleMapper.getPage(map, pageNum, pageSize);
        List<VehicleDto> dealerBeanDtoList = Convert.toVehicleBeanDto(vehicleBeanList);
        return new Paged<VehicleDto>(dealerBeanDtoList, pageCount, pageSize);
    }

    /**
     * 获取所有车型信息（包含车系、品牌）
     *
     * @return
     */
    @Override
    public List<VehicleNameBizDto> getAllVehicleMake() {
        return vehicleMapper.getAllVehicleMake();
    }
}
